<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $menu_model = D('Menu');
        $top_menu = $menu_model->query_top_menu();
        $left_menu = $menu_model->get_easyui_menu_accordion(0,get_module_session('admin', 'user_role'));
        $this->assign('menus', $top_menu);
        $left_str = '';
        foreach($left_menu as $v){
            $left_str .= $v['content'];
        }
        $this->assign('left_menu', $left_str);
        $this->display('x_index');
    }

    public function get_tree_menu(){
        $get_data = filterInput($_GET);
        if(!isset($get_data['pid'])){
            echo 'no menu pid parm in request';
            return;
        }
        $menu_model = D('Menu');
        $role = get_module_session('admin', 'user_role');
        $menu = $menu_model->get_easyui_menu_tree_json($get_data['pid'], $role);
        echo json_encode($menu);
//        echo '<li><span>Friend</span></li>';
    }

    public function get_accordion_menu(){
        $data = filterInput($_GET);
        if(!isset($data['pid'])){
            echo 'no menu pid parm in request';
            return;
        }
        $menu_model = D('Menu');
        $role = get_module_session('admin', 'user_role');
        $menu = $menu_model->get_easyui_menu_accordion($data['pid'], $role);
        echo json_encode($menu);
    }

    public function top(){
        $menu_model = D('Menu');
        $top_menu = $menu_model->queryField('parentid', 0);
        $this->assign('menus', $top_menu);
        $this->display();
    }

    public function left(){
        $get_data = filterInput($_GET);
        if(!isset($get_data['pid'])){
            echo 'no menu pid parm in request';
            return;
        }
        $pid = $get_data['pid'];
        $menu = get_left_menu_ace_admin($pid);
        $this->assign('menu', $menu);
        $this->display();
    }

    public function right(){
        $this->display();
    }

    public function query_all_menu(){
        echo D('Menu')->get_easyui_menu_tree();
    }

    public function index_panel(){

    }
}